//
//  LGConserveConfirmViewController.m
//  LuxuryGoods
//
//  Created by 刘星辰 on 2018/5/26.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "LGConserveConfirmViewController.h"
#import "LGDoubleLabelCell.h"
#import "LGAddressCell.h"
#import "LGConfirmFormBar.h"
#import "LGHandbagDetailCell.h"
#import "LGConfirmFormHeader.h"
@interface LGConserveConfirmViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)LGConfirmFormBar *bar;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UIView *footer;
@end

@implementation LGConserveConfirmViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"确认订单";
    
    
    [self.view addSubview:self.bar];
    [self.bar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(50);
        make.bottom.offset(HOMEBAR_HEIGHT);
    }];
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(0, 0, 50 + HOMEBAR_HEIGHT, 0));
    }];
    
    
    self.tableView.tableFooterView = self.footer;
    
    
    [self.bar makeAttributedMoney:@"20"];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0)
    {
        return 1;
    }
    else if (section == 1 || section == 2)
    {
        return 1;
    }
    else if (section == 3)
    {
        return 1;
    }
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0 || section == 1 || section == 2)
    {
        return 34.f;
    }
    return CGFLOAT_MIN;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    LGConfirmFormHeader *view = [LGConfirmFormHeader createFromXib];
    if (section == 0)
    {
        view.titleLab.text = @"鉴定商品";
        view.line.hidden = YES;
    }
    else if (section == 1)
    {
         view.titleLab.text = @"寄件地址";
        view.line.hidden = NO;
    }
    else if (section == 2)
    {
         view.titleLab.text = @"回寄地址";
        view.line.hidden = NO;
    }
    else
    {
        return nil;
    }
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return 138.5f;
    }
    else if (indexPath.section == 1 || indexPath.section == 2)
    {
           return 60.f;
    }
    return 50.f;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0)
    {
        //创建xib复用单元格
        static NSString * ID = @"LGHandbagDetailCell";
        LGHandbagDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"LGHandbagDetailCell" owner:self options:nil] firstObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        [cell makeAttributedMoney:@"23"];
        cell.line.hidden = (indexPath.row == 1)?(YES):(NO);
        
        return cell;
    }
    
    else if (indexPath.section == 1 || indexPath.section == 2)
    {
        //创建xib复用单元格
        static NSString * ID = @"LGAddressCell";
        LGAddressCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"LGAddressCell" owner:self options:nil] firstObject];
        }
        return cell;
    }
    else if (indexPath.section == 3)
    {
        //创建xib复用单元格
        static NSString * ID = @"LGDoubleLabelCell";
        LGDoubleLabelCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"LGDoubleLabelCell" owner:self options:nil] firstObject];
        }
        [cell isHidenArrows:NO];
        return cell;
    }
    
    else
    {
        //创建xib复用单元格
        static NSString * ID = @"LGDoubleLabelCell";
        LGDoubleLabelCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"LGDoubleLabelCell" owner:self options:nil] firstObject];
        }
        [cell isHidenArrows:NO];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (LGConfirmFormBar *)bar
{
    if (_bar == nil)
    {
        _bar = [LGConfirmFormBar createFromXib];
        _bar.buyAction = ^{
            
        };
    }
    return _bar;
}

- (UITableView *)tableView
{
    if (_tableView == nil)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATOR_HEIGHT) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = UIColorFromRGB(0xEFF1F1);
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
                _tableView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
    }
    return _tableView;
}

- (UIView *)footer
{
    if (_footer == nil)
    {
        _footer = [UIView new];
        _footer.backgroundColor = WHITE_COLOR;
        UILabel * label =  [[UILabel alloc] init];
        label.text = @"温馨提示：\n  请将需要鉴定的包包，通过快递邮寄到上述地址，我们按照到件的顺序，依次进行鉴定。鉴定完成后，我们将按照您填写的回寄地址，将鉴定结果和包包一同回寄给您。";
        label.font = FONT(15);
        label.textColor = TEXT_COLOR_1;
        label.textAlignment = NSTextAlignmentLeft;
        label.numberOfLines = 0;
        [_footer addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(15, 15, 15, 15));
        }];
        
       CGSize size = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH - 15 * 2, CGFLOAT_MIN)];
        _footer.size = CGSizeMake(size.width, size.height + 15 *2);
    }
    return _footer;
}

@end
